package core

import "github.com/spf13/viper"

type setting struct {
	vp *viper.Viper
}

// 获取系统设置
func NewSetting() (*setting, error) {
	vp := viper.New()
	vp.SetConfigName("config")
	vp.AddConfigPath("internal/")
	vp.SetConfigType("yaml")
	if err := vp.ReadInConfig(); err != nil {
		return nil, err
	}
	return &setting{vp: vp}, nil
}

// 读取配置文件
func (s *setting) ReadSection(k string, v interface{}) error {
	return s.vp.UnmarshalKey(k, v)
}
